//
//  CartoonTableListCollectionViewCell.swift
//  UUCartoon
//
//  Created by Galaxy on 2021/5/7.
//  Copyright © 2021 qykj. All rights reserved.
//

import UIKit
import Kingfisher
class CartoonTableListCollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var leftImg: UIImageView!
    @IBOutlet weak var titleLab: UILabel!
    @IBOutlet weak var authorLab: UILabel!
    @IBOutlet weak var categoryLab: UILabel!
    @IBOutlet weak var timeLab: UILabel!
    // 最新更新
    @IBOutlet weak var numLab: UILabel!
//    @IBOutlet weak var titleConstraintHeight: NSLayoutConstraint!
    // 在排序中，右侧按钮要隐藏
    @IBOutlet weak var rightImg: UIImageView!
    // 排序中，要显示，其他情况隐藏
    @IBOutlet weak var rankLab: UILabel!
    @IBOutlet weak var rankView: UIView!
    @IBOutlet weak var backViewConstraintWidth: NSLayoutConstraint!
    
    var model:CartoonModel = CartoonModel(){
        didSet{
            if Tool.init().isPhone() {
                // 手机上，单行显示
                backViewConstraintWidth.constant = screenW
            }else{
                backViewConstraintWidth.constant = 375
            }
            titleLab.text = model.name
            let modifier = AnyModifier { request in
                var r = request
                r.setValue(urlArr[self.model.type.rawValue], forHTTPHeaderField: "Referer")
                return r
            }
            leftImg.kf.setImage(with: URL.init(string: model.imgUrl), placeholder: UIImage.init(named: "placeholder"), options: [.requestModifier(modifier)], completionHandler: nil)
            authorLab.text = model.author
            categoryLab.text = model.category
            timeLab.text = model.time
            if model.is_rank == true {
                rankView.isHidden = false
                numLab.isHidden = true
                rightImg.isHidden = true
            }else{
                rankView.isHidden = true
                numLab.isHidden = false
                rightImg.isHidden = false
            }
            if model.is_collect || model.is_history {
                numLab.isHidden = true
                rightImg.isHidden = true
                timeLab.text = ["优酷漫画","漫画猫","无敌漫画"][model.type.rawValue]
            }else{
                if model.type == .ykmh {
                    let numArr = model.num.split(separator: " ")
                    if (numArr.count != 0) {
                        numLab.text = String(numArr[0])
                    }
                }else{
                    numLab.text = model.num
                }
            }
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
}
